package com.example.redo.androidpower;

import android.content.Context;
import android.content.pm.PackageManager;

/**
 * Created by redo on 2016/2/28.
 */
public class Hello {
    protected static final String SAY_HELLO_PERMISSION = "com.example.redo.androidpower.permission.hello";

    public static void sayHello(Context context) {
        int i = context.checkCallingOrSelfPermission(SAY_HELLO_PERMISSION);

        /**PackageManager有两个属性:
         *PERMISSION_GRANTED:返回有权限
         *PERMISSION_DENIED:返回没有权限
         *注册了(permission)没给权限(uses-permission)，或者给了权限没注册，
         * 或者两者都没有。。这都会导致 PERMISSION_DENIED条件成立，成真
         */
        if (i == PackageManager.PERMISSION_DENIED) {
            System.out.println(SAY_HELLO_PERMISSION);
        } else
            System.out.println("hello");
    }
}
